define(function (require, exports, module) {

    var $ = require("lib/zepto");
    var Register = require("lib/com/register");

    var CLS_REGISTER = 'input-wrap';
    var CLS_HEAD = 'h-wrap';
    var CLS_HEAD2 = 'h-wrap2';
    var SN_NAME = (APP.snName || 'SN码') + ': ';

	var info = Tida.appinfo;
	if(info.isTmall){
		$.dialog({
			content : '本活动在手淘环境下有更好的体验，是否打开手机淘宝？',
			title : '不是手机淘宝',
			ok : function() {
			  Tida.openClient(window.location.href,"taobao");
			  return false;
			},
			cancel : function() {
			},
			lock : false
		});
	}
	$(".poupClose").on("click",function(){
		$(".poupFadIn").hide();
	});
	$(".poupTitleMune").on("click",function(){
		var id = $(this).attr("id");
		$(".poupMain").hide();
		switch(id){
			case "actionExpBtn":
				$(".slideBarTip").css({"left":".6rem"});
				$("#ruleBox").show();
			break;
			case "ranBtn":
				$(".slideBarTip").css({"left":"5rem"});
				$("#rankBox").show();
			break;
			case "prizeBtn":
				$(".slideBarTip").css({"left":"9.6rem"});
				$("#awardBox").show();
			break;
		}
	});
	// 幻灯片
    // require("lib/swipe");
    /**
     * 对话框
     * @param container：对话框容器
     * @constructor
     */
    function Dialog(container) {
        this.container = $(container);
        this.rendered = false;
        this.currentType = 0;

        this.render();
    }

    // 对话框类型
    Dialog.TYPE = {
        register: 1, // 抽奖开始前填写用户信息
        take: 2, // 领取奖品
        takeOK: 3, // 领取成功
        again: 4, // 再砸一次
        noDayTimes: 5, // 天次数用完
        noAllTimes: 6, // 总次数用完
        passwdExchange: 7, // 密码兑奖
        exchangeOK: 8, // 兑奖OK
        weixinOK: 9, // 微信红包领取OK
		
        inputOrder: 10, // 要求输入订单号领奖
        medalExcange: 11, // 用奖章兑奖
        jifenExcange: 12, // 用积分兑奖
        collectItems: 13, // 收藏商品兑奖
        addCartItems: 14,// 收藏商品兑奖
        friendShow: 15,// 炫耀得奖
        checkWl: 16,// 检查地址和物流
        orderExchange: 17,// 订单兑换奖品
        orderChance: 18,// 订单兑换抽奖次数
        jifenChance: 19,// 订单兑换抽奖次数
        addCartChance: 20,// 订单兑换抽奖次数
        signDays: 21// 签到日历
    };

    Dialog.prototype = {
        constructor: Dialog,
        // 渲染
        render: function () {
            var _self = this;
            if (!_self.rendered) {
                _self._init();

                _self.rendered = true;
            }
        },
        // 初始化
        _init: function () {
            var _self = this,
                container = _self.container;
            _self.head = container.find('.' + CLS_HEAD);
            _self.body = container.find('section');
            _self.foot = container.find('footer');

            // 抽奖开始前填写用户信息
            if (APP.uid <= 0 && APP.regFirst) {
                _self.renderUI(Dialog.TYPE.register);
            }
        },
        // 初始化注册
        _initRegister: function (callback) {
            var _self = this,
                container = _self.container;
            // 显示注册字段
            container.find("." + CLS_REGISTER).show();

            new Register(container, function (data) {
                data = data || {};
                if (data.success && data.uid) {
                    APP.uid = data.uid;
                    APP.point = data.point;
                    callback && callback();
                } else if (data.error) {
                    alert(data.error);
                }
            });
        },
        // 绑定事件
        _bindUI: function (options) {
            var _self = this;

            switch (_self.currentType) {
                case Dialog.TYPE.register:
                    _self._initRegister(function () {
                        _self.hide();
                        // 隐藏注册字段
                        _self.container.find("." + CLS_REGISTER).hide();
                    });
                    break;
                case Dialog.TYPE.take:
					// 兑奖
					$('#J_SubmitBtn').off("click").on("click", function () {
						_self.renderUiSwitch(options);
					});
                    // 关闭
                    $('#J_CloseBtn').off("click").on("click", function () {
                        _self.hide();
						//_self.refresh();
                    });
                    break;
				case Dialog.TYPE.checkWl:
					// 保存
					$('#J_SubmitBtn').off("click").on("click", function () {
						var true_name = $(".true_name").val();
						var mobile = $(".mobile").val();
						var cmbProvince = $("#cmbProvince").val();
						var cmbCity = $("#cmbCity").val();
						var cmbArea = $("#cmbArea").val();
						var address = $(".address").val();
						var picker = cmbProvince+" "+cmbCity+" "+cmbArea;
						var options = {"name":true_name,"mobile":mobile,"picker":picker,"address":address};
						_self._saveAddress(options);
						// _self.renderUI(Dialog.TYPE.exchange, options);
					});
                    // 关闭
                    $('#J_CloseBtn').off("click").on("click", function () {
                        _self.hide();
						//_self.refresh();
                    });
					break;
                case Dialog.TYPE.weixinOK:
                case Dialog.TYPE.exchangeOK:
                case Dialog.TYPE.takeOK:
                    // 刷新
                    $('#J_CloseBtn').off("click").on("click", function () {
                        _self.hide();
                    });
                    break;
                case Dialog.TYPE.again:
                case Dialog.TYPE.noDayTimes:
                case Dialog.TYPE.noAllTimes:
                    // 关闭
                    $('#J_CloseBtn').off("click").on("click", function () {
                        _self.hide();
                        options.callback && options.callback();
                    });
                    break;
				case Dialog.TYPE.jifenChance:
					$('#J_CloseBtn').off("click").on("click", function () {
					 _self.hide();
					 $(".poupFadIn").show();
					});
					$(".jifen_chance").on("click",function(){
						var gift = $(this).attr("data-gift");
						var jifen = $(this).attr("data-jifen");
						options.gift=gift;
						options.jifen=jifen;
						_self._jifenChance(options);
					});
					break;
				case Dialog.TYPE.orderChance:
					$('#J_CloseBtn').off("click").on("click", function () {
					 _self.hide();
					 $(".poupFadIn").show();
					});
					$('#J_SubmitBtn').off("click").on("click", function () {
                        _self._orderChance(options);
                    });
					break;
				case Dialog.TYPE.addCartChance:
					$('#J_CloseBtn').off("click").on("click", function () {
						$(".poupFadIn").show();
						_self.hide();
                    });
					$('.image').on("click", function () {
						var iid = $(this).attr("data-iid");
						options.iid=iid;
                        _self._addCartChance(options);
                    });
					break;
                case Dialog.TYPE.passwdExchange:
                    $('#J_CloseBtn').off("click").on("click", function () {
                        _self.hide();
						// _self.refresh();
                    });
                    $('#J_SubmitBtn').off("click").on("click", function () {
                        _self._handleExchange(options);
                    });
					break;
				case Dialog.TYPE.inputOrder:
					$('#J_SubmitBtn').off("click").on("click", function () {
						var mygid = $(this).attr("data-mygid");
						var gid = $(this).attr("data-gid");
						var getway = $(this).attr("data-getway");
						var options = {"mygid":mygid,"gid":gid,"getway":getway};
                        _self._orderExchange(options);
                    });
				break;
				case Dialog.TYPE.medalExcange:
				case Dialog.TYPE.jifenExcange:
					$('#J_CloseBtn').off("click").on("click", function () {
                        _self.hide();
                    });
					$('#J_SubmitBtn').off("click").on("click", function () {
						var mygid = $(this).attr("data-mygid");
						var gid = $(this).attr("data-gid");
						var getway = $(this).attr("data-getway");
						var options = {"mygid":mygid,"gid":gid,"getway":getway};
                        _self._jifenExcange(options);
                    });
				break;
				case Dialog.TYPE.addCartItems:
					$('#J_SubmitBtn').off("click").on("click", function () {
						var mygid = $(this).attr("data-mygid");
						var gid = $(this).attr("data-gid");
						var getway = $(this).attr("data-getway");
						var options = {"mygid":mygid,"gid":gid,"getway":getway};
                        _self._handleTake(options);
                    });
					$('#J_CloseBtn').off("click").on("click", function () {
                        _self.hide();
                    });
					$('.image').on("click", function () {
						var mygid = $(this).attr("data-mygid");
						var gid = $(this).attr("data-gid");
						var getway = $(this).attr("data-getway");
						var iid = $(this).attr("data-iid");
						var options = {"mygid":mygid,"gid":gid,"getway":getway,"iid":iid};
                        _self._addCartItems(options);
                    });
				break;
				case Dialog.TYPE.collectItems:
					$('#J_SubmitBtn').off("click").on("click", function () {
						var mygid = $(this).attr("data-mygid");
						var gid = $(this).attr("data-gid");
						var getway = $(this).attr("data-getway");
						var options = {"mygid":mygid,"gid":gid,"getway":getway};
                        _self._handleTake(options);
                    });
					$('#J_CloseBtn').off("click").on("click", function () {
                        _self.hide();
                    });
					$('.image').on("click", function () {
						var mygid = $(this).attr("data-mygid");
						var gid = $(this).attr("data-gid");
						var getway = $(this).attr("data-getway");
						var iid = $(this).attr("data-iid");
						var options = {"mygid":mygid,"gid":gid,"getway":getway,"iid":iid};
                        _self._collectItems(options);
                    });
				break;
				case Dialog.TYPE.friendShow:
					$('#J_CloseBtn').off("click").on("click", function () {
						_self.hide();
                    });
					
					$('#J_SubmitBtn').off("click").on("click", function () {var mygid = $(this).attr("data-mygid");
						var gid = $(this).attr("data-gid");
						var getway = $(this).attr("data-getway");
						var show_title = $(this).attr("data-show_title");
						var show_content = $(this).attr("data-show_content");
						var show_pic = $(this).attr("data-show_pic");
						var options = {"mygid":mygid,"gid":gid,"getway":getway,"show_title":show_title,"show_content":show_content,"show_pic":show_pic};
                        
						_self.hide();
						_self._friendShow(options);
					});
				break;
				case Dialog.TYPE.signDays:
					$(".js-changmon").on("click",function(){
						var mon = $(this).attr("data-mon");
						var day = new Date(mon);
						options.signList = {};
					    options.curdate = day.getFullYear()+"-"+(day.getMonth()+1)+"-"+day.getDate();
						$.getJSON(APP.urls.mission,options,function(json){
							options.signList = json.setting;
							_self.renderUI(Dialog.TYPE.signDays, options);
						});
					});
					$(".gift").on("click",function(){
						alert("加油，连续签到可领取奖品哦！");
					});
					$(".giftok").on("click",function(){
						var eid = $(".eid").val();
						var gid = $(this).attr("data-gid");
						var date = $(this).attr("data-date");
						_self._signLingJiang({"gid":gid,"date":date,"eid":eid});
					});
					$(".js-buqian").on("click",function(){
						var date = $(this).attr("data-day");
						_self._signBuQian({"curdate":date});
					});
					$(".js-calqd,#J_SubmitBtn").on("click",function(){
						_self._signQianDao();
					});
					$(".js-close-cal").on("click",function(){
						_self.hide();
					});
				break;
            }

            // 奖品属性链接
            $('[data-role="link"]', _self.container).off("click").on("click", function (e) {
                var btn = $(e.currentTarget);
                _self.handleUrlBtn({c_url: btn.attr("data-url"), c_attr: btn.attr("data-attr"), snid: btn.attr("data-id")});
            });
        },
		renderUiSwitch :function (options){
			var _self = this;
			switch(options.getway){
				case "friend_show":
					$.getJSON(APP.urls.gift+'&a=get_gift_friendshow',options, function (json) {
						if(!json.hasError){
							options.show_title=json.show.show_title;
							options.show_content=json.show.show_content;
							options.show_pic=json.show.pic_url;
							_self.renderUI(Dialog.TYPE.friendShow, options);
						}else{
							alert("抱歉，没有获取到奖品信息");
						}
					});
					break;
				case "password":
					_self.renderUI(Dialog.TYPE.passwdExchange, options);
					break;
				case "look":
					_self.renderUI(Dialog.TYPE.takeOK,options);
					break;
				case "order":
					_self.renderUI(Dialog.TYPE.inputOrder, options);
					break;
				case "jifen":
					$.getJSON(APP.urls.gift+'&a=get_gift_jifen',options, function (json) {
						if(json.jifen){
							options.jifen = json.jifen;
							_self.renderUI(Dialog.TYPE.jifenExcange, options);
						}else{
							alert("抱歉，没有获取到奖品信息");
						}
					});
					break;
				case "metal":
					$.getJSON(APP.urls.gift+'&a=get_gift_metal',options, function (json) { 
						if(json){
							options.medal_quant = json.medal_quant;
							options.medal_name = json.medal_name;
							_self.renderUI(Dialog.TYPE.medalExcange, options);
						}else{
							alert("抱歉，没有获取到奖品信息");
						}
					});
					break;
				case "collect":
					$.getJSON(APP.urls.gift+'&a=get_gift_collect',options, function (json) {
						if(json){
							options.collect_items=json.collect_items;
							_self.renderUI(Dialog.TYPE.collectItems, options);
						}else{
							alert("抱歉，没有获取到奖品信息");
						}
					});
					break;
				case "addcart" :
					$.getJSON(APP.urls.gift+'&a=get_gift_addcart',options, function (json) {
						if(json){
							options.cart_items=json.cart_items;
							_self.renderUI(Dialog.TYPE.addCartItems, options);
						}else{
							alert("抱歉，没有获取到奖品信息");
						}
					});
					break;
				case "checkwl":
					// 查看物流
					$.getJSON(APP.urls.user+'&a=checkwl',options, function (json) {
						if(json){
							_self.renderUI(Dialog.TYPE.checkWl, {"title": "检查物流","myadd":json.myadd,"msg": json.msg,"area":json.area,"wlid":json.wlinfo.wlid,"wlcode":json.wlinfo.wlcode});
						}else{
							alert("抱歉，没有获取到奖品信息");
						}
					});
					break;
				default:
					$.post(APP.urls.exchange, options, function (data) {
						if(data.hasError){
							alert("抱歉，领奖失败"+data.msg);
						}else{
							alert("领奖成功！"+data.msg);
							_self.refresh();
						}
					}, 'json');
					break;
			}
		},
        /**
         * 渲染内容
         * @param type：对话框类型
         * @param options：对话框内容配置项
         */
        renderUI: function (type, options) {
            var _self = this,
                options = options || {},
                headCls = CLS_HEAD,
                headHTML = '',
                bodyHTML = '',
                footHTML = '';
			var loadHtml = function(items)
			{
				if(items){
					var html='';
						html+=("<div class=\"page-swipe\">");
						html+=("<header>");
						html+=("  <div id=\"slider\" class=\"swipe\" style=\"visibility: visible;\">");
						html+=("    <div class=\"swipe-wrap\">");
					for(var i=0;i<items.length;i++){
						html += "<figure><h2>"+items[i][2]+"</h2><div class=\"wrap\">";
						html += "<div class=\"image\" data-iid=\""+items[i][0]+"\" data-gid=\""+options.gid+"\" data-mygid=\""+options.mygid+"\" data-getway=\""+options.getway+"\" style=\"background:url("+items[i][1]+") center no-repeat;background-size: cover\"> </div>";
						html += "</div></figure>";
					}
						html+=("    </div>");
						html+=("  </div>");
						html+=("  <nav>");
						html+=("    <ul id=\"position\">");
					for(var i=0;i<items.length;i++){
						html+=("      <li class=\""+(i==0?"on":"")+"\"></li>");
					}
						html+=("    </ul>");
						html+=("  </nav>");
						html+=("</header>");
						html+=("</div>");
				}else{
					html="<center>没有可以加入购物车的商品</center>";
				}
				return html;
			},
			calUtil = 
			{
					getDaysInmonth : function(iMonth, iYear){
					  var dPrevDate = new Date(iYear, iMonth, 0);
					  return dPrevDate.getDate();
					},
					bulidCal : function(iYear, iMonth) {
					  var aMonth = new Array();
					  aMonth[0] = new Array(7);
					  aMonth[1] = new Array(7);
					  aMonth[2] = new Array(7);
					  aMonth[3] = new Array(7);
					  aMonth[4] = new Array(7);
					  aMonth[5] = new Array(7);
					  aMonth[6] = new Array(7);
					  var dCalDate = new Date(iYear, iMonth - 1, 1);
					  var iDayOfFirst = dCalDate.getDay();
					  var iDaysInMonth = calUtil.getDaysInmonth(iMonth, iYear);
					  var iVarDate = 1;
					  var d, w;
					  aMonth[0][0] = "日";
					  aMonth[0][1] = "一";
					  aMonth[0][2] = "二";
					  aMonth[0][3] = "三";
					  aMonth[0][4] = "四";
					  aMonth[0][5] = "五";
					  aMonth[0][6] = "六";
					  for (d = iDayOfFirst; d < 7; d++) {
						aMonth[1][d] = iVarDate;
						iVarDate++;
					  }
					  for (w = 2; w < 7; w++) {
						for (d = 0; d < 7; d++) {
						  if (iVarDate <= iDaysInMonth) {
							aMonth[w][d] = iVarDate;
							iVarDate++;
						  }
						}
					  }
					  return aMonth;
					},
					ifHasSigned : function(signList,day){
					  var signed = new Array();
					  for(var i=0;i<signList.length;i++){
						  if(signList[i].signDay==day){
							  signed["type"]= signList[i].signType;
							  signed["giftid"]= signList[i].giftId;
							  switch(signList[i].giftDay){
								  case 1 : signed["giftcss"] = " giftok "; break;
								  case 2 : signed["giftcss"] = " gift "; break;
							  }
						  }
					  }
					  return signed ;
					},	
					getPreMonth : function(date) {
						/**
						 * 获取上一个月
						 *
						 * @date 格式为yyyy-mm-dd的日期，如：2014-01-25
						 */
						var arr = date.split('-');
						var year = arr[0]; //获取当前日期的年份
						var month = arr[1]; //获取当前日期的月份
						var day = arr[2]; //获取当前日期的日
						var days = new Date(year, month, 0);
						days = days.getDate(); //获取当前日期中月的天数
						var year2 = year;
						var month2 = parseInt(month) - 1;
						if (month2 == 0) {
							year2 = parseInt(year2) - 1;
							month2 = 12;
						}
						var day2 = day;
						var days2 = new Date(year2, month2, 0);
						days2 = days2.getDate();
						if (day2 > days2) {
							day2 = days2;
						}
						if (month2 < 10) {
							month2 = '0' + month2;
						}
						var t2 = year2 + '-' + month2 + '-' + day2;
						return t2;
					},      
					getNextMonth : function (date) {
						/**
						 * 获取下一个月
						 *
						 * @date 格式为yyyy-mm-dd的日期，如：2014-01-25
						 */  
						var arr = date.split('-');
						var year = arr[0]; //获取当前日期的年份
						var month = arr[1]; //获取当前日期的月份
						var day = arr[2]; //获取当前日期的日
						var days = new Date(year, month, 0);
						days = days.getDate(); //获取当前日期中的月的天数
						var year2 = year;
						var month2 = parseInt(month) + 1;
						if (month2 == 13) {
							year2 = parseInt(year2) + 1;
							month2 = 1;
						}
						var day2 = day;
						var days2 = new Date(year2, month2, 0);
						days2 = days2.getDate();
						if (day2 > days2) {
							day2 = days2;
						}
						if (month2 < 10) {
							month2 = '0' + month2;
						}
					
						var t2 = year2 + '-' + month2 + '-' + day2;
						return t2;
					},
					drawCal : function(iYear, iMonth ,signList) {
					  var myMonth = calUtil.bulidCal(iYear, iMonth);
					  var htmls = new Array();
					  var mon = iMonth>=10?iMonth:"0"+iMonth;
					  htmls.push("<div class='sign_main' id='sign_layer'>");
					  htmls.push("<div class='sign_succ_calendar_title'>");
					  htmls.push("<div class='calendar_month_next js-changmon' data-mon=\""+this.getNextMonth(iYear+"-"+mon+"-"+"01")+"\"></div>");
					  htmls.push("<div class='calendar_month_prev js-changmon' data-mon=\""+this.getPreMonth(iYear+"-"+mon+"-"+"01")+"\"></div>");
					  htmls.push("<div class='calendar_month_span'>"+iYear+"年"+iMonth+"月</div>");
					  htmls.push("<span class=\"ks-ext-close-x js-close-cal\">关闭</span>");
					  htmls.push("</div>");
					  htmls.push("<div class='sign' id='sign_cal'>");
					  htmls.push("<table>");
					  htmls.push("<tr>");
					  htmls.push("<th>" + myMonth[0][0] + "</th>");
					  htmls.push("<th>" + myMonth[0][1] + "</th>");
					  htmls.push("<th>" + myMonth[0][2] + "</th>");
					  htmls.push("<th>" + myMonth[0][3] + "</th>");
					  htmls.push("<th>" + myMonth[0][4] + "</th>");
					  htmls.push("<th>" + myMonth[0][5] + "</th>");
					  htmls.push("<th>" + myMonth[0][6] + "</th>");
					  htmls.push("</tr>");
					  var d, w;
					  for (w = 1; w < 7; w++) {
						htmls.push("<tr>");
						for (d = 0; d < 7; d++) {
						  var day = myMonth[w][d]>=10?myMonth[w][d]:"0"+myMonth[w][d];
						  var ifHasSigned = calUtil.ifHasSigned(signList,myMonth[w][d]);
						  var giftDayCss = ifHasSigned.giftcss?ifHasSigned.giftcss:"";
						  var giftId = ifHasSigned.giftid?" data-gid=\""+ifHasSigned.giftid+"\" data-date=\""+iYear+"-"+iMonth+"-"+myMonth[w][d]+"\"":"";
						  // console.log(ifHasSigned);
						  if(ifHasSigned.type==1){
							giftDayCss=giftDayCss?giftDayCss:"on";
							htmls.push("<td class='"+giftDayCss+"' "+giftId+">" + (!isNaN(myMonth[w][d]) ? myMonth[w][d] : " ") + "</td>");
						  }else if(ifHasSigned.type==2){ //允许补签
							htmls.push("<td class='"+giftDayCss+"' "+giftId+"><input data-tp=\"buqian\" data-day=\""+iYear+"-"+mon+"-"+day+"\" class=\"btn btn-mini btn-primary js-buqian\" type=\"button\" value=\"补签\"></td>");
						  }else if(ifHasSigned.type==3){ //允许领奖
							htmls.push("<td class='"+giftDayCss+"'  "+giftId+"><input data-tp=\"lingjiang\" data-day=\""+iYear+"-"+mon+"-"+day+"\" class=\"btn btn-mini btn-warning js-buqian\" type=\"button\" value=\"领奖\"></td>");
						  }else if(ifHasSigned.type==4){ //已经补签
							giftDayCss=giftDayCss?giftDayCss:"on_bu";
							htmls.push("<td class='"+giftDayCss+"' "+giftId+">" + (!isNaN(myMonth[w][d]) ? myMonth[w][d] : " ") + "</td>");
						  }else if(ifHasSigned.type==5){ //不在本月
							htmls.push("<td class=\"on_la\">" + (!isNaN(myMonth[w][d]) ? myMonth[w][d] : " ") + "</td>");
						  }else if(ifHasSigned.type==6){ //允许签到
							htmls.push("<td class='"+giftDayCss+"' "+giftId+"><input class=\"btn btn-mini js-calqd\" type=\"button\" value=\"签到\"></td>");
						  }else if(ifHasSigned.type==7){ //等待奖品
							htmls.push("<td class=\"gift\">" + (!isNaN(myMonth[w][d]) ? myMonth[w][d] : " ") + "</td>");
						  }else {
							htmls.push("<td class='"+giftDayCss+"' "+giftId+">" + (!isNaN(myMonth[w][d]) ? myMonth[w][d] : " ") + "</td>");
						  }
						}
						htmls.push("</tr>");
					  }
					  htmls.push("</table>");
					  htmls.push("</div>");
					  htmls.push("</div>");
					  return htmls.join('');
					}
				};
            _self.currentType = type;
            switch (_self.currentType) 
			{
                case Dialog.TYPE.signDays:
					var curdate = new Date(options.curdate);
					var signList = options.signList;
					bodyHTML = calUtil.drawCal(curdate.getFullYear(),curdate.getMonth() + 1,signList);
					footHTML = '<a href="javascript:;" id="J_SubmitBtn" class="btn-yes">签到</a>';
					break;
                case Dialog.TYPE.checkWl:
					headHTML = '<p>'+options.title+"</p>";
					bodyHTML = '<center>'+options.msg+'</center>';
					bodyHTML += '<br /><div class="exchange-wrap">';
					if(options.wlcode){
						bodyHTML += '快递公司：<input type="text" value="'+options.wlcode+'" readonly />物流单号：<input type="text" value="'+options.wlid+'" readonly />';
						var readonly="readonly";
					}else{
						bodyHTML += "抱歉，您的奖品还未发出。请留下您的详细地址，耐心等待。";
						var readonly="";
					}
					options.myadd = options.myadd || {"name":"","address":"","tel":""};
					bodyHTML += "</div>";
					bodyHTML += '<br /><div class="exchange-wrap"><input type="text" class="true_name" '+readonly+' value="'+options.myadd.name+'" placeholder="请输入真实姓名" required/></div>';
					bodyHTML += '<br /><div class="exchange-wrap"><input type="text" class="mobile"  '+readonly+' placeholder="请输入电话" required value="'+options.myadd.tel+'" /></div>';
					bodyHTML += '<br /><div class="exchange-wrap">省：<select id="cmbProvince" '+readonly+' ></select>';
					bodyHTML += '市：<select id="cmbCity" '+readonly+' ></select>';
					bodyHTML += '区：<select id="cmbArea" '+readonly+' ></select>';
					bodyHTML += '</div>';
					bodyHTML += '<br /><div class="exchange-wrap"><input type="text" class="address"  '+readonly+' placeholder="请输入详细地址" required value="'+options.myadd.address+'" /></div>';
                    footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-no">关闭</a><a href="javascript:;" id="J_SubmitBtn" class="btn-yes">保存地址</a>';
				break;
                case Dialog.TYPE.friendShow:
					headHTML = '<p>亲，向朋友炫耀一下才可以领奖哦！</p>';
					bodyHTML = '<div class="exchange-wrap" style="height:80px;width:80px;margin:0 auto;"><img src="'+options.show_pic+'" style="height:80px;"/></div>';
					bodyHTML += '<br /><div class="exchange-wrap"><input type="text" name="show_title" value="'+options.show_title+'" placeholder="请输入订单号" required/></div>';
					bodyHTML += '<br /><div class="exchange-wrap"><input type="text" name="show_content" placeholder="请输入订单号" required value="'+options.show_content+'" /></div>';
                    footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-no">取消</a><a href="javascript:;" data-show_pic="'+options.show_pic+'" data-show_title="'+options.show_title+'" data-show_content="'+options.show_content+'" data-gid="'+options.gid+'"  data-mygid="'+options.mygid+'" data-getway="'+options.getway+'" id="J_SubmitBtn" class="btn-yes">炫耀</a>';
					break;
                case Dialog.TYPE.addCartItems:
					if(options.cart_items.length>0){
						headHTML = '<p>亲，您需要将以下商品加入购物车后领取奖品。</p>';	
						bodyHTML = loadHtml(options.cart_items);
					}else{
						headHTML = '<p>亲，请领取奖品！</p>';
						bodyHTML = '<center>您已把所有商品加入购物车</center>';
					}
					if(options.cart_items.length==0){
						footHTML = "<a href=\"javascript:;\" id=\"J_CloseBtn\" class=\"btn-no\">关闭</a><a href=\"javascript:;\" data-gid=\""+options.gid+"\" data-mygid=\""+options.mygid+"\" data-getway=\""+options.getway+"\" id=\"J_SubmitBtn\" class=\"btn-yes\">领取</a>";
					}else{
						footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-no">关闭</a>';
					}
					break;
                case Dialog.TYPE.collectItems:
					if(options.collect_items.length>0){
						headHTML = '<p>亲，您需要收藏以下商品后领取奖品。</p>';
						bodyHTML = loadHtml(options.collect_items);
					}else{
						headHTML = '<p>亲，请领取奖品！</p>';
						bodyHTML = '<center>您已收藏所有商品</center>';
					}
					if(options.collect_items.length==0){
						footHTML = "<a href=\"javascript:;\" id=\"J_CloseBtn\" class=\"btn-no\">关闭</a><a href=\"javascript:;\" data-gid=\""+options.gid+"\" data-mygid=\""+options.mygid+"\" data-getway=\""+options.getway+"\" id=\"J_SubmitBtn\" class=\"btn-yes\">领取</a>";
					}else{
						footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-no">关闭</a>';
					}
					break;
                case Dialog.TYPE.medalExcange:
                    headHTML = '<p>亲，您需要使用'+options.medal_quant+'个'+options.medal_name+'奖章兑换奖品，确定兑换吗？</p>';
					footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-no">关闭</a><a href="javascript:;" data-gid="'+options.gid+'"  data-mygid="'+options.mygid+'" data-getway="'+options.getway+'" id="J_SubmitBtn" class="btn-yes">奖章兑换</a>';
					break;
                case Dialog.TYPE.jifenExcange:
                    headHTML = '<p>亲，您需要使用'+options.jifen+'积分兑换奖品，确定兑换吗？</p>';
					footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-no">关闭</a><a href="javascript:;" data-gid="'+options.gid+'"  data-mygid="'+options.mygid+'" data-getway="'+options.getway+'" id="J_SubmitBtn" class="btn-yes">积分兑换</a>';
					break;
                case Dialog.TYPE.passwdExchange:
                    headHTML = '<p>请输入密码来兑换本奖品：</p>';
                    bodyHTML = '<div class="exchange-wrap"><i></i><input type="text" name="snpwd" placeholder="兑奖密码" required/></div>';
                    footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-no">取消</a><a href="javascript:;" id="J_SubmitBtn" class="btn-yes">兑奖</a>';
                    break;
                case Dialog.TYPE.inputOrder:
                    headHTML = '<p>亲，请填写订单号领奖~~~~</p>';
					bodyHTML = '<div class="exchange-wrap"><i class="order"></i><input type="text" name="order" placeholder="请输入订单号" required/></div>';
                    footHTML = '<a href="javascript:;" data-gid="'+options.gid+'"  data-mygid="'+options.mygid+'" data-getway="'+options.getway+'" id="J_SubmitBtn" class="btn-yes">领奖</a>';
					break;
                case Dialog.TYPE.orderChance:
                    headHTML = '<p>订单号兑换抽奖机会</p>';
					bodyHTML = '<div class="exchange-wrap"><input type="text" name="order" placeholder="请输入订单号" required/></div>';
                    footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-no">关闭</a><a href="javascript:;"  id="J_SubmitBtn" class="btn-yes">兑换</a>';
					break;
                case Dialog.TYPE.jifenChance:
                    headHTML = '<p>积分兑换抽奖机会</p>';
					// bodyHTML = '<div class="exchange-wrap">';
					var j=0;
					for(var i=0;i<options.setting.dh.length;i++){
					  if(options.setting.dh[i]["gift"]>0 && options.setting.dh[i]["gift_type"]==7){ //此处只能兑换抽奖次数
						j++;
						bodyHTML += "<div class=\"exchange-wrap\"><div class=\"jifen\">"+options.setting.dh[i]["jifen"]+'积分兑换'+options.setting.dh[i]["gift_name"]+"</div><button class='jifen_chance' data-gift='"+options.setting.dh[i]["gift"]+"' data-jifen='"+options.setting.dh[i]["jifen"]+"'>兑换</button> </div><br />";
					  }
					}
					if(j==0){
						bodyHTML+="<center>没有可兑换的抽奖机会</center>";
					}
					// bodyHTML += '</div>';
                    footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-no">关闭</a>';
					break;
                case Dialog.TYPE.addCartChance:
					if(options.cart_cfg && options.cart_cfg.tms_cartadd>0){
					headHTML = '<p>亲，每加入购物车1件商品，可获得'+options.cart_cfg.tms_cartadd+'次抽奖机会，最多可获得'+options.cart_cfg.tms_cartadd_limit+'次机会。</p>';	
					}else{
						headHTML = '<p>抱歉，购物车抽奖已关闭</p>';
					}
					bodyHTML = loadHtml(options.cart_items);
					footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-no">关闭</a>';
					break;
                case Dialog.TYPE.register:
                    headHTML = '<p>亲，填写信息抽奖哟~~~~</p>';
                    bodyHTML = $('#J_Register').html();
                    footHTML = '<a href="javascript:;" id="J_SubmitBtn" class="btn-yes">开始抽奖</a>';
                    break;
                case Dialog.TYPE.take:
                    // if (APP.uid > 0) {
                        // if (options.c_url || !APP.onmobile) { // 奖品属性有url或非手机端兑奖
                            // headHTML = '<p class="prize-shop-wrap"><p><span>'+ (options.c_attr == 3 ? '微信红包' : options.giftname) +'</span></p>';
                            // bodyHTML = '<div class="prize-top">' + (options.c_attr == 3 ? options.giftname : SN_NAME + options.sn) + '</div>';
                            // bodyHTML += '<div class="prize-wrap"><ul><li>' + options.level + '</li><li><img src="' + options.giftpic + '"/></li><li>' + options.giftname + '</li></ul>';
                            // if (options.c_url) {
                                // footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-no">关闭</a>'+ _self._initUlrBtnHtml(options);
                            // } else {
                                // footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-yes">知道啦</a>';
                            // }
                        // } else {
                            headHTML = '<p>' + options.giftname + '</p>';
                            bodyHTML = '<div class="prize-wrap"><ul><li>' + options.level + '</li><li><img src="' + options.giftpic + '"/></li><li>' + options.giftname + '</li></ul></div>';
                            footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-no">关闭</a><a href="javascript:;" id="J_SubmitBtn" class="btn-yes">立即兑奖</a>';
                        // }
                    // } else {
                        // headHTML = '<p>' + options.giftname + '</p>';
                        // bodyHTML = '<div class="prize-wrap"><ul><li>' + options.level + '</li><li><img src="' + options.giftpic + '"/></li><li>' + options.giftname + '</li></ul><hr/></div>';
                        // bodyHTML += $('#J_Register').html();
                        // footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-no">关闭</a><a href="javascript:;" id="J_SubmitBtn" class="btn-yes">' + ((options.c_attr == 2 || options.c_attr == 3) ? '领取红包' : '领取') +'</a>';
                    // }
                    break;
                case Dialog.TYPE.takeOK:
                    headHTML = '<p>领取成功</p>';
                    bodyHTML = '<div class="take-ok-wrap"><p><span>卡号：' + options.cardno + '</span><span>密码：' + options.secret + '</span></div>';
                    footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-yes">知道啦</a>';
                    break;
                case Dialog.TYPE.again:
                    headCls += ' ' + CLS_HEAD2;
                    headHTML = '<p class="hit-again-wrap"><i></i>' + options.giftname + '</p>';
                    footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-yes">再砸一次</a>';
                    break;
                case Dialog.TYPE.noDayTimes:
                case Dialog.TYPE.weixinOK:
                    headCls += ' ' + CLS_HEAD2;
                    headHTML = '<p class="noday-times-wrap"><span>' + options.giftname + '</span></p>';
                    footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-yes">知道啦</a>';
                    break;
                case Dialog.TYPE.noAllTimes:
                    headCls += ' ' + CLS_HEAD2;
                    headHTML = '<p class="noall-times-wrap"><i></i><span>' + options.giftname + '</span></p>';
                    footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-yes">知道啦</a>';
                    break;
                case Dialog.TYPE.exchangeOK:
                    headHTML = '<p class="prize-shop-wrap"><p><span>'+ SN_NAME + options.sn +'</span></p>';
                    footHTML = '<a href="javascript:;" id="J_CloseBtn" class="btn-no">取消</a>'+ _self._initUlrBtnHtml(options);
                    break;
            }

            _self.head.html(headHTML).attr("class", headCls);
            _self.body.html(bodyHTML);
            _self.foot.html(footHTML);

            _self._bindUI(options);
            _self.show();
			if(_self.currentType == Dialog.TYPE.checkWl)
			{
					// 渲染三级行政区
					if(options.wlcode){
						$("#cmbProvince").html("<option>"+options.myadd.province+"</option>");
						$("#cmbCity").html("<option>"+options.myadd.city+"</option>");
						$("#cmbArea").html("<option>"+options.myadd.city_part+"</option>");
					}else{
						require("lib/jsAddress");
						addressInit(options.area,'cmbProvince', 'cmbCity', 'cmbArea', options.myadd.province, options.myadd.city, options.myadd.city_part);
					}
			}
			if((_self.currentType == Dialog.TYPE.collectItems && options.collect_items.length>0) || ((_self.currentType == Dialog.TYPE.addCartItems || _self.currentType == Dialog.TYPE.addCartChance) && options.cart_items.length>0)) 
			{
			      // 渲染幻灯片
				  require("lib/swipe");
				  var slider =
				  Swipe(document.getElementById('slider'), {
					auto: 3000,
					continuous: true,
					callback: function(pos) {
					  var i = bullets.length;
					  while (i--) {
						bullets[i].className = ' ';
					  }
					  bullets[pos].className = 'on';
					}
				  });
				  var bullets = document.getElementById('position').getElementsByTagName('li');
			}
        },
		//保存收货地址
		_saveAddress:function(options){
			var _self = this;
			$.getJSON(APP.urls.user+"&a=save_addr",options, function (json) {
				// Tida.hideLoading();
				if(json.hasError){
					alert("保存地址出错！");
				}else{
					alert("已保存地址，请等待发放奖品");
					_self.refresh();
				}
			});
		},
		// 炫耀领奖
		_friendShow: function(options){
			var way = 1;
			var show = 1;
			var _self = this;
			$.getJSON(APP.urls.gift+"&a=pickup&way="+way+"&show="+show,options, function (json) {
				// Tida.hideLoading();
				if(json.hasError){
					alert("加入购物车失败，请打开手机淘宝重试");
				}else{
					alert("加入购物车成功");
					_self.refresh();
				}
			});
			// 炫耀领奖
			Tida.share({
			'title':options.show_title, // 分享标题 在来往和微信好友中有标题显示
			'content': options.show_content, //分享的内容
			'url': options.show_url, // 跳转地址，分享的内容跳转的url
			'image':options.show_pic, // 图片地址,客户端可能需要根据url下载图片再分享。需要CDN上的完整图片链接.图片会模糊掉的话注意传高清图片：TAE CDN地址后面加上后缀_620X10000.jpg可以解决
			'wxIsAvailable': 1, // 是否添加微信通道。为真时添加微信入口。仅手淘支持 取值为真或假。老版本使用这个参数进行设置。如果需要微信建议与weixinshare一起设置为真
			'weixinshare': 1, // 是否添加微信通道。为真时添加微信入口。仅手淘支持 取值为真或假。在手淘5.2.7上使用，后续将废弃
			'shareType': 1, // 为1时只能分享到通讯录。仅手淘支持
			'wxImage': 1, // 天猫IOS客户端分享到微信/微信朋友圈的图片有限制，这里默认自动转为200x200的。若不是正方形图片且需要自己传递该图片,并遵循天猫客户端图片的限制规则（不要过大 阿里的CDN上的）
			//渠道控制新增参数
			'targets' : [  2, 3, 4, 6, 7],//新的控制分享渠道的参数，以前的参数weixinshare等将逐渐废弃，请不要使用。参数值： 0 通讯录；1 复制；2 微博；3 微信；4 朋友圈；5 二维码；6 来往；7 旺信；
			//微信分享新增参数
			'weixinAppId' : "wxfe8929c7097f09cc",//微信分享appId
			'weixinMsgType':"webpage",//微信分享方式：text文案分享（title必传）、image图片分享（image必传）、webpage图文分享（title、content、image、url必传）
		 
			}, function(data){
				// share=false;
				//{"msg":Error,errorCode:-1,errorMessage:""}//未登录
				//{ret:{retCode:1,retMsg:取消},errorCode:1,errorMessage:取消}
				//{ret:{retCode:0,retMsg:成功},data:{type:18},errorCode:0,errorMessage:成功} 
				//data:{type:18} //复制口令
				//data:{type:17} //复制链接
				//data:{type:4} //微信
				//data:{type:6} //微信朋友圈
				//data:{type:15} //qq好友
				//data:{type:1} //微博
				//data:{type:14} //支付宝好友
				//data:{type:9} //短信
				
				var show;
				if(info.isTmall){
					show = data.type;
					if(data.errorCode==-1){
						alert('<p>您没有登录或已取消，请重试。</p>'+(data.errorMessage?data.errorMessage:""));
					}else if(data.errorCode==1){
						alert('<p>您已取消，请重新分享。</p>'+(data.errorMessage?data.errorMessage:""));
					}else if(data.errorCode==0){
						alert("您已分享成功，请领取奖品");
					}
				}
				// 淘宝
				// target:QR,errorCode:0 二维码
				// {target:COPY,errCode:0} 复制淘口令
				// {target:WEIXIN,errCode:0} 微信
				// {target:WXFRIEND,errCode:0} 微信
				// {target:CONTACTS,errCode:0} 手机联系人
				// errorMessage:微信分享要求有图片,platform:extimeline,ret:fail,errorCode:-1
				// alert(data.errorCode);
				if(info.isTaobao){
					code = data.target;
					if(data.errorCode==0){
						alert("您已分享成功，请领取奖品");
					}else{
						alert('<p>您没有登录或已取消，请重试。</p>'+(data.errorMessage?data.errorMessage:""));
					}
				}
				var way = info.name;
				$.getJSON(APP.urls.gift+"&a=pickup&way="+way+"&show="+show,options, function (json) {
					// Tida.hideLoading();
					if(json.hasError){
						alert("加入购物车失败，请打开手机淘宝重试");
					}else{
						alert("加入购物车成功");
						_self.refresh();
					}
				});
				// 分享接口调用成功，在手机淘宝下面该回调仅代表API执行成功，非分享成功与否的回调。 分享成功与否正在开发中，敬请期待
			});
		},
		// 加购物车获得抽奖次数
		_addCartChance:function(options){
			options.isvExt="cartChanceShopmobile_"+Math.round(new Date().getTime())+""+parseInt(1000*Math.random()) ;	
			var tida = {
				"itemId": options.iid,
				"isvExt": options.isvExt //可区分业务的唯一识别码
			};
			options.cart_items=null;
			options.mis="cartadd_check";
			// options.isvExt="cartChanceShopmobile_1469537931213472";
			Tida.showLoading("正在检查是否成功...");
			Tida.cart(tida, function (data) {
				Tida.hideLoading();
				if(data.ret=="HY_NO_HANDLER"){
					alert("抱歉，只能在手机淘宝内操作。");
					return;
				}
				if(data.data=="businissType:0"){
					Tida.showLoading("加载中...");
					//需要等待1秒
					var timeout=0;
					var intid = setInterval(function(){
						timeout++;
						if((timeout%6)==0){
							$.getJSON(APP.urls.user+"&a=mission",options, function (json) {
								if(json.setting=="waitting"){
									Tida.showLoading("正在检查是否成功...");
									if(timeout>20){
										window.clearInterval(intid);
										alert("等待购物车数据超时，请重试");
									}
								}else{
									window.clearInterval(intid);
									alert(json.msg);
								}
							});
						}
					},200);
				}else{
					alert("请加入购物车！");
				}
			});
		},
		// 加购物车领奖
		_addCartItems: function(options){
			var tida = {
				itemId: options.iid
			};
			Tida.showLoading("加载中...");
			Tida.cart(tida, function (data) {
				// {data:businissType:0,ret:HY_SUCCESS,errorCode:0}//加购
				// {data:businissType:1,ret:HY_SUCCESS,errorCode:0}//购买
				// {errorCode:6,errorMsg:用户取消该操作}//购买
				Tida.hideLoading();
				// alert(JSON.stringify(data))
				if(data.ret=="HY_NO_HANDLER"){
					alert("抱歉，只能在手机淘宝内操作。");
					return;
				}
				if(data.data=="businissType:0"){
					Tida.showLoading("加载中...");
					$.getJSON(APP.urls.user+"&a=addcart_item&iid="+options.iid+"&gid="+options.gid, function (json) {
						Tida.hideLoading();
						if(json.hasError){
							alert("加入购物车失败，请打开手机淘宝重试");
						}else{
							alert("加入购物车成功");
						}
					});
				}else{
					alert("请加入购物车！");
				}
			});
		},
		// 收藏商品领奖
		_collectItems: function(options){
			var tida = {
				itemId: options.iid,
				action: "check"
			};
			Tida.showLoading("加载中...");
			Tida.itemFavor(tida,function(data){
				
				// alert(JSON.stringify(data))
				// {errorCode:3,errorMsg:notsupport}
				// {data:isFav:false,itemId:23423432,ret:HY_SUCCESS,errorCode:0}
				
				if(data.errorCode==3){
					Tida.hideLoading();
					alert("抱歉，只能在手机淘宝收藏，请打开手机淘宝收藏本宝贝");
					return;
				}
				if(data.errorCode==0){
					$.getJSON(APP.urls.user+"&a=collect_item&iid="+tida.itemId+"&gid="+options.gid, function (json) {
						Tida.hideLoading();
						if(json.hasError){
							alert("收藏失败，请打开手机淘宝重试");
						}else{
							alert("收藏成功");
						}
					});
					return;
				}
				alert("收藏失败！原因："+data.ret+data.errorMsg+data.errorCode);
			});
		},
        // 处理领取奖品
        _handleTake: function (options) {
            var _self = this,
                options = options || {};
            // 领取
            $.post(APP.urls.exchange, options, function (data) {
                data = data || {};
                if (!data.hasError) {
					 _self.refresh();
                } else{
                    alert(data.msg);
                }

            }, 'json');
        },
		// 积分兑换奖品
		_jifenExcange:function(options){
			var _self = this,
                options = options || {};
            $.post(APP.urls.exchange, options, function (data) {
                data = data || {};
                if (data.hasError) {
                    alert(data.msg);
                } else if (data.code=="need_address") {
                    alert(data.msg+"领奖成功请输入地址");
                } else if (data.code=="check_address") {
                    alert(data.msg+"领奖成功请检查地址");
                } else if (!data.hasError) {
					alert(data.msg);
                    _self.refresh();
                }
            }, 'json');
		},
		// 积分兑换抽奖机会
		_jifenChance:function(options){
			options.do_jifen_exchange=true;
			options.mis="jifen";
			$.getJSON(APP.urls.mission,options,function(json){
				alert(json.msg);
			});
		},
		// 订单兑换抽奖次数
		_orderChance:function(options){
			var _self = this,
                options = options || {},
                jInput = _self.container.find("input[name='order']"),
                order = jInput.val();
				options.oid=order;
            if (order == "") {
                alert(jInput.attr("placeholder") + "不能为空！");
                return false;
            }
			$.getJSON(APP.urls.mission,options,function(json){
				alert(json.msg);
			});
		},
		// 订单兑奖
		_orderExchange:function(options){
			var _self = this,
                options = options || {},
                jInput = _self.container.find("input[name='order']"),
                order = jInput.val();
            if (order == "") {
                alert(jInput.attr("placeholder") + "不能为空！");
                return false;
            }
            $.post(APP.urls.exchange, {"uid": APP.uid, "order": order,"mygid":options.mygid,"gid":options.gid,"getway":options.getway}, function (data) {
                data = data || {};
                if (data.hasError) {
                    alert(data.msg);
                } else if (!data.hasError) {
                    _self.refresh();
                }
            }, 'json');
		},
        // 处理兑奖
        _handleExchange: function (options) {
            var _self = this,
                options = options || {},
                jInput = _self.container.find("input[name='snpwd']"),
                passwd = jInput.val();
            if (passwd == "") {
                alert(jInput.attr("placeholder") + "不能为空！");
                return false;
            }

            // 兑奖
            $.post(APP.urls.exchange, {"uid": APP.uid, "passwd": passwd,"mygid":options.mygid,"gid":options.gid,"getway":options.getway}, function (data) {
                data = data || {};
                if (!data.hasError) {
                    _self.refresh();
                } else if (data.hasError) {
                    alert(data.msg);
                }
            }, 'json');
        },
		//读取并显示收货地址
		_renderCheckAddress: function(options) {
            this.renderUI(Dialog.TYPE.weixinOK, {title: "请检查您的收奖地址是否正确"});
        },
		// 签到
		_signQianDao:function(options){
			$.getJSON(APP.urls.signday,options,function(json){
				alert(json.msg);
			});
		},
		// 补签
		_signBuQian:function(options){
			$.getJSON(APP.urls.signpassday,options,function(json){
				alert(json.msg);
			});
		},
		// 签到领奖
		_signLingJiang:function(options){
			var gid = options.gid;
			var date = options.date;
			$.getJSON(APP.urls.signlingjiang,options,function(json){
				alert(json.msg);
			});
		},
        // 处理奖品属性有链接的按钮
        handleUrlBtn: function (options) {
            var _self = this,
                options = options || {},
                url = options.c_url;

            if (options.c_attr == 3) {
                // 领取微信红包
                $.post(url, {uid: APP.uid, snid: options.snid}, function (data) {
                    data = data || {};
                    if (data.success) {
                        _self._renderWeixinOK();
                    } else if (data.error) {
                        alert(data.error);
                    }
                }, 'json');
            } else if (options.c_attr == 1 || options.c_attr == 2) {
                // 旺铺代金券和微盟红包，要走销毁SN码步骤
                $.post(url, {uid: APP.uid, snid: options.snid}, function (data) {
                    data = data || {};
                    if (data.success) {
                        location.href = data.url;
                    } else if (data.error) {
                        alert(data.error);
                    }
                }, 'json');
            }
        },
        // 渲染微信红包提示
        _renderWeixinOK: function() {
            this.renderUI(Dialog.TYPE.weixinOK, {title: "领取成功，系统已经派发给您，<br/>请及时在公众号内查看"});
        },
        // 组装奖品属性有链接的按钮HTML
        _initUlrBtnHtml: function (options) {
            var options = options || {},
                snid = options.snid || '',
                url = options.c_url || '',
                attr = options.c_attr || 0,
                htmlArr = [];
            htmlArr.push('<a href="javascript:;" data-role="link"');
            htmlArr.push(' data-id="'+ snid +'"');
            htmlArr.push(' data-url="'+ url +'"');
            htmlArr.push(' data-attr="'+ attr +'"');
            htmlArr.push(' class="btn-yes">');
            switch(attr) {
                case 1:
                    htmlArr.push('立即使用');
                    break;
                case 2:
                    htmlArr.push('查看红包');
                    break;
                case 3:
                    htmlArr.push('领取红包');
                    break;
            }
            htmlArr.push('</a>');
            return htmlArr.join('');
        },
        // 显示
        show: function () {
            this.container.show();
        },
        // 隐藏
        hide: function () {
            this.container.hide();
        },
        // 重新加载
        refresh: function () {
            var cc=window.location.href;
            window.NEWSHREF=cc.split('&time=')[0];
            window.location.href=window.NEWSHREF+'&time='+Math.random();
        }
    };

    module.exports = Dialog;
});
